/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package j_table;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
/**
 *
 * @author Lenovo
 */
public class J_DiagonalLayout implements LayoutManager{//自定义布局管理器
    public void addLayoutComponent(String name,Component comp)
    {

    }
    public void removeLayoutComponent(Component comp)
    {

    }
    public Dimension preferredLayoutSize(Container parent)
    {
        Dimension d=null;
        Insets s=parent.getInsets();
        Dimension dp=new Dimension(s.left+s.right,s.top+s.bottom);
        Component c;
        int n=parent.getComponentCount();
        for(int i=0;i<n;i++)
        {
            c=parent.getComponent(i);
            if(c.isVisible())
            {
                d=c.getPreferredSize();
                dp.width+=d.width;
                dp.height+=d.height;
            }
        }
         return dp;
    }
    public Dimension minimumLayoutSize(Container parent)
    {
        Dimension d=null;
        Insets s =parent.getInsets();
        Dimension dp=new Dimension(0,0);
        Component c;
        int n=parent.getComponentCount();
        for(int i=0;i<n;i++)
        {
            c=parent.getComponent(i);
            if(c.isVisible())
            {
                d=c.getPreferredSize();
                if(d.width>dp.width)
                    dp.width=d.width;
                if(d.height>dp.height)
                    dp.height=d.height;
            }
        }
        dp.width+=(s.left+s.right);
        dp.height+=(s.top+s.bottom);
        return dp;
    }
    public void layoutContainer(Container parent)
    {
        int i;
        int n=parent.getComponentCount();
        Component c;
        Insets s=parent.getInsets();
        Dimension d;
        Dimension dp=parent.getSize();
        Dimension dr=preferredLayoutSize(parent);
        Dimension dc=new Dimension(s.left,s.top);
        Dimension dg=new Dimension(dp.width-dr.width,dp.height-dr.height);
        if(n>1)
        {
            dg.width/=(n-1);
            dg.height/=(n-1);
        }
//******************************************************************************
        //设置控件位置及大小操作
        for(i=0;i<4;i++)
        {
            c=parent.getComponent(i);
            if(c.isVisible())
            {
                d=c.getPreferredSize();
                c.setBounds(dc.width+50,dc.height,90,30);
                dc.width+=100;
                //dc.height+=(dg.height+dg.height);
            }
        }
        c=parent.getComponent(4);
        if(c.isVisible())
            {
                d=c.getPreferredSize();
                c.setBounds(dc.width-350,dc.height+50,d.width+35,d.height+300);
                //dc.width+=100;
                //dc.height+=(dg.height+dg.height);
            }
        for(i=5;i<7;i++)
        {
            c=parent.getComponent(i);
            d=c.getPreferredSize();
            c.setBounds(dc.width-280,dc.height+540,90,30);
            dc.width+=100;
            //dc.height+=(dg.height+dg.height);
        }
//*************************************************************************
    }
    /**
     * @param args the command line arguments
     */
  
}
